package com.earnings.okhttputils.utils.ui.activity.user;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.earnings.R;
import com.earnings.okhttputils.utils.OkHttp.OkHttpUtils;
import com.earnings.okhttputils.utils.UrlConstant.HttpUrl;
import com.earnings.okhttputils.utils.User;
import com.earnings.okhttputils.utils.god.GodLeftHandBaseActivity;
import com.earnings.okhttputils.utils.god.Listener.GodOnClickListener;
import com.earnings.okhttputils.utils.https.HttpMap;
import com.earnings.okhttputils.utils.https.HttpObjectCallback;
import com.earnings.okhttputils.utils.ui.dialog.InfoDialog;
import com.earnings.okhttputils.utils.utils.CommonUtil;

import java.util.Map;


/*
财币
 */

public class UserTreasureActivity extends GodLeftHandBaseActivity implements GodOnClickListener {


    private ImageView head;
    private TextView balance;

    @Override
    protected int onCreateLayoutId() {
        return R.layout.activity_user_treasure;
    }

    @Override
    protected void init() {
        setTopStyleView();
        setTitle("财币");
        showRightTextView("明细");

        setOnClickListener( this,R.id.btnTreasure1,R.id.btnTreasure2, R.id.btnTreasure3 ,R.id.top_right_tv,R.id.question);

    }




    public void loadBalance(){
        showProgress();
        Map map=new HttpMap( getContext() );
        OkHttpUtils.post().params( map ).url( HttpUrl.USER_RICH_DATA_URL ).build().execute( new HttpObjectCallback<User>(getContext()) {
            @Override
            public void onSuccess(User object, String msg) {
                setText( R.id.balance, object.getRich() );
                User user=CommonUtil.getUser();
                user.setRich( object.getRich() );
                user.setWithdrawal( object.getWithdrawal() );
                user.setFreeze( object.getFreeze() );
                user.setRate( object.getRate() );
                CommonUtil.commitUser( user );
                dismissProgress();
            }

            @Override
            public void onFail(int code, String msg) {
                dismissProgress();
            }
        } );
    }

    @Override
    protected void onResume() {
        super.onResume(); loadBalance();
    }

    @Override
    public void OnClickListener(View view) {
        int i = view.getId();
        if (i == R.id.btnTreasure1) {
            skipActivity(UserTreasureTurnPriceActivity.class);
        } else if (i == R.id.btnTreasure2) {
            skipActivity(UserTreasureTurnActivity.class);
        } else if (i == R.id.btnTreasure3) {
            skipActivity(UserTreasureContributionActivity.class);
        } else if (i == R.id.top_right_tv) {
                skipActivity( UserTreasureListActivity.class );
        }else if (i == R.id.question) {
            InfoDialog info=new InfoDialog(getContext(),"财币账户增加时，扣除10%服务费;\n获得财币单笔0.5以内的不扣除");
            info.setTitle("财币说明");
            info.show();
        }
    }
}
